package com.polaris.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.net.userService
import com.polaris.live.resp.back_resp.UserVipDetailResp
import com.polaris.live.resp.base.ListResp
import com.polaris.live.widget.refresh.OnListListener

/**
 * VipDetailViewModel
 *
 * @author Created by 天晴 on 2024/12/10/022 16:01
 */
class VipDetailViewModel : BaseViewModel(), OnListListener {

    val vipDetailLiveData = MutableLiveData<ResultState<ListResp<UserVipDetailResp>>>()
    val pageSize = 20  // 每页记录数

    private fun getVipDetail(
        pageNumber: Int,
        pageSize: Int = this.pageSize,
    ) {
        request({ userService.getVipDetail(pageNumber, pageSize) }, vipDetailLiveData)
    }

    override fun onRefresh() {
        getVipDetail(pageNumber = 0)
    }

    override fun onLoadMore(pageIndex: Int) {
        getVipDetail(pageNumber = pageIndex)
    }
}